<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    var arr = [
      { id: 1, name: '系统管理', pid: 0 },
      { id: 2, name: '用户管理', pid: 0 },
      { id: 3, name: '注册', pid: 2 },
      { id: 4, name: '登录', pid: 2 },
      { id: 5, name: '系统配置', pid: 1 },
      { id: 6, name: '财务管理', pid: 0 },
      { id: 7, name: '添加财务', pid: 6 },
      { id: 8, name: '删除财务', pid: 6 },
      { id: 9, name: 'aaaa', pid: 8 },
      { id: 10, name: 'bbbb', pid: 8 },
      { id: 11, name: 'bbbb', pid: 10 },
    ];

    function abc(arr, pid) {
      var list = arr.filter(item => {
        return item.pid == pid
      });
      list.map(a => {
        arr.forEach(function (b) {
          if (a.id == b.pid) {
            a.children = abc(arr, b.pid)
          }
        })
      })
      return list;
    }
    console.log(abc(arr, 0));
  </script>
</body>

<ml>